﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jy123.Model;
using Jy123.BLL.Public;
using System.Data;

namespace Jy123.BLL.Line
{
    public class Line
    {
        public List<Model.Public_Line> GetLineByPage(int pageSize, int currentPage, string filter, out List<int?> counts)
        {
            MPagination mp = new MPagination
            {
                Tables = "Public_Line",
                CurrentPage = currentPage,
                PageSize = pageSize,
                PrimaryKey = "ID",
                Filter = filter,
                Fields="*",
                Sort="ID"
            };
            DataSet ds = Pagination.GetList(mp, out counts);
            BLL.Public_Line BLLLine = new Public_Line();
            List<Model.Public_Line> listLine = DsToList(ds);
            return listLine;
        }

        private List<Model.Public_Line> DsToList(DataSet ds)
        {
            List<Jy123.Model.Public_Line> modelList = new List<Jy123.Model.Public_Line>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                Jy123.Model.Public_Line model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Jy123.Model.Public_Line();
                    if (ds.Tables[0].Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[n]["ID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["FSportType"].ToString() != "")
                    {
                        model.FSportType = int.Parse(ds.Tables[0].Rows[n]["FSportType"].ToString());
                    }
                    model.LName = ds.Tables[0].Rows[n]["LName"].ToString();
                    model.LModel = ds.Tables[0].Rows[n]["LModel"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }
    }
}

